<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml" 
      xmlns:ui="http://java.sun.com/jsf/facelets"
	   xmlns:f="http://java.sun.com/jsf/core" 
      xmlns:h="http://java.sun.com/jsf/html" 
      xmlns:a4j="http://richfaces.org/a4j"
	   xmlns:rich="http://richfaces.org/rich" 
      xmlns:composite="http://java.sun.com/jsf/composite">

<!-- INTERFACE -->
<composite:interface>
	<composite:attribute name="classe" />
	<composite:attribute name="atributo" />
	<composite:attribute name="atributos" />
	<composite:attribute name="mapTipoCampo" />
	<composite:attribute name="bean"/>	
</composite:interface>

<!-- IMPLEMENTATION -->
<composite:implementation>
<rich:panel id="pnlAtributo" styleClass=".form" header="Registro de atributos para a classe #{cc.attrs.classe.nome}" headerClass="header" columnClasses="label, none">
	<h:panelGrid columns="2" columnClasses="titleCell">

		<h:panelGroup><div style="text-align:right; width:70px;"><h:outputLabel value="Nome:" /></div></h:panelGroup>
		<h:inputText id="nome" value="#{cc.attrs.atributo.nome}" style=" width : 500px;" />

		<h:panelGroup><div style="text-align:right; width:70px;"><h:outputLabel value="Descricao:" /></div></h:panelGroup>
		<h:inputTextarea id="descricaoCampo" value="#{cc.attrs.atributo.descricao}" rows="4" cols="80" />
				
		<h:panelGroup><div style="text-align:right; width:70px;"><h:outputLabel value="Nome Coluna:" /></div></h:panelGroup>
		<h:inputText id="nomeColuna" value="#{cc.attrs.atributo.nomeColuna}" style=" width : 500px;" />
	</h:panelGrid>
		
	<h:panelGrid columns="4"  >
		<h:panelGroup><div style="text-align:right; width:70px;"><h:outputLabel value="Tamanho:" /></div></h:panelGroup>
		<h:inputText id="tamanho" value="#{cc.attrs.atributo.tamanho}" style=" width : 100px;" />

		<h:panelGroup><div style="text-align:right; width:70px;"><h:outputLabel value="Tipo Campo:" /></div></h:panelGroup>
		<h:selectOneMenu id="tipoCampo" value="#{cc.attrs.atributo.tipoCampo}" style=" width : 200px;">
			<f:selectItems value="#{cc.attrs.mapTipoCampo}" />
		</h:selectOneMenu>

		<h:panelGroup><div style="text-align:right; width:70px;"><h:outputLabel value="Versao:" /></div></h:panelGroup>
		<h:inputText id="versaoCampo" value="#{cc.attrs.atributo.versao}" style=" width : 200px;" />
		
		<h:panelGroup><div style="text-align:right; width:70px;"><h:outputLabel value="É opcional?" /></div></h:panelGroup>
		<h:selectOneRadio value="#{cc.attrs.atributo.ehOpcional}">
		   	<f:selectItem itemValue="true" itemLabel="Sim" />
		   	<f:selectItem itemValue="false" itemLabel="Não"/>
		</h:selectOneRadio>
	  	
	</h:panelGrid>				
		
	<h:panelGrid columns="2" columnClasses="titleCell">
		<h:panelGroup><div style="text-align:right; width:70px;"><h:outputLabel value="Valor:" /></div></h:panelGroup>
		<h:inputText id="valor" value="#{cc.attrs.atributo.valor}" style=" width : 335px;" />

		<h:panelGroup><div style="text-align:right; width:70px;"><h:outputLabel value="Texto Livre:" /></div></h:panelGroup>
		<h:inputTextarea id="textoLivreCampo" value="#{cc.attrs.atributo.textoLivre}" rows="4" cols="80" />
	</h:panelGrid>
	
	<h:panelGrid columns="3" >
		<h:commandButton id="btnAddAtributo" action="#{cc.attrs.bean.addAtributo}" render="listaAtributos, pnlAtributo"
			value="Adicionar atributo" styleClass="register" title="Clique para adicionar atributo"/>
		<h:messages styleClass="messages" errorClass="invalid" infoClass="valid" warnClass="warning" globalOnly="true" />
	</h:panelGrid>	
	
</rich:panel>

<rich:collapsiblePanel id="listaAtributos" header="Campos" headerClass="header" title="Click to expand/collapse">
   <h:panelGroup rendered="#{empty cc.attrs.atributos}">
      <em>No registered atributos.</em>
   </h:panelGroup>
   <rich:dataTable var="item" value="#{cc.attrs.atributos}" rendered="#{not empty cc.attrs.atributos}" style="width : 100%">
	   <rich:column>
			<a4j:commandLink action="#{cc.attrs.bean.buscaAtributo}" styleClass="no-decor" render="atributoPanel" > Visualiza
	         <f:setPropertyActionListener target="#{cc.attrs.bean.idAtributo}" value="#{item.id}"/>
	      </a4j:commandLink>
	   </rich:column>
	   <rich:column>
	      <f:facet name="header">Id</f:facet>	#{item.id}
	   </rich:column>
	   <rich:column>
	      <f:facet name="header">Name</f:facet>		#{item.nome}
	   </rich:column>
	   <rich:column>
	      <f:facet name="header">Tamanho</f:facet>	#{item.tamanho}
	   </rich:column>
	   <rich:column>
	      <f:facet name="header">Tipo</f:facet>		#{item.tipoCampo}
	   </rich:column>
	</rich:dataTable>
</rich:collapsiblePanel>
</composite:implementation>
</html>
